let city = ''
$.ajax({
  url: "../../../js/city.json",
  data: { action: "jQueryAjax" },
  type: "GET",
  async: false,
  success: function (data) {
    city = data
  },
  //返回数据的格式
  dataType: "json"
})
const enterpriseVue = new Vue({
  el: '#app',
  data() {
    return {
      pickerOptions: pickerOptions,
      rules: {
        Brand_Name: [{
          required: true,
          message: '请输入品牌名称',
          trigger: 'blur',
        }]
      },
      form: {
        Traceability_Base_SerialNumber:'',
        Traceability_Base_Name:'',
        Traceability_Base_Production:'',
        Cultural_Information:'',
        Traceability_Base_Address:'',
        People_Number:'',
        Video_URL:'/muer.mp4',
        Enterprise_Info_SerialNumber:$.cookie("enterprise"),
      },
      data:{
        name: "video"
      },
      fileList: [],
      city,
      // 被选中的市数据
      cityList: [],
      // 被选中的县数据
      areaList: [],
      isdisabled: true,
      selectProvince: {},
      selectCity: {},
      selectArea: {},
      address: '',
      FileList:[],
      videoUrl:'',
      loading: false
    }
  },
  mounted() {

  },
  methods: {
    submitForm(formName) {
      let _this = this
      this.$refs[formName].validate((valid) => {
        if (valid) {
          _this.loading = true
          $.ajax({
            url: DomainName + '/getAddAction',
            type: 'POST',
            data: {
              Data:JSON.stringify({traceabilitybase_info:[_this.form]}),
              token:$.cookie('token')
            },
            success: function (res) {
              console.log('提交结果', res)
              _this.$message.success("提交成功")
              window.history.go(-1);
            },
            error: function () {
              _this.$message.error("操作失败，请稍后再试")
            },
            complete: function (XMLHttpRequest) {
              _this.loading = false
              if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
              }
            }
          })
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    selectProvinceFun(event) {
      console.log(event)
      if (event) {
        this.cityList = event.children
      } else {
        this.cityList = []
      }
      this.areaList = []
    },
    selectCityFun(event) {
      console.log(event)
      if (event) {
        this.areaList = event.children
      } else {
        this.areaList = []
      }
    },
    selectAreaFun(event) {
      if (event) {
        console.log(event)
        this.isdisabled = false
      } else {
        this.isdisabled = true
      }
    },
    selectAddress(event) {
      if (event && event != '' && this.selectArea.label != undefined) {
        this.form.Traceability_Base_Address = this.selectProvince.label + '/'
          + this.selectCity.label + '/'
          + this.selectArea.label + '/'
          + this.address
      }
    },
    upload(file){
      let _this = this
      console.log(file);
      console.log(file.name);
      console.log(file.size / 1024 / 1024);
      console.log(file.type);
      console.log(this.FileList);
      const isLt10M = file.size / 1024 / 1024 < 10; // 检查文件大小是否超过10M  
      // if (!isLt10M) {  
      //   this.$message.error('上传视频大小不能超过10MB哦!'); // 如果超过10M，则弹出错误提示信息  
      //   return false; // 取消上传操作  
      // } else {  
      //   // 如果文件大小不超过10M，则继续执行上传操作  
      // } 
    },
    handleVideoSuccess(response, file, fileList) {  
      console.log(response);
      console.log(file);
      console.log(fileList);
      this.videoUrl = response; 
      this.$message.success('上传成功');  
    }, 
  }
})